//
//  SSDetailsHeadImageView.m
//  textDemo
//
//  Created by Esther on 2017/2/20.
//  Copyright © 2017年 Esther. All rights reserved.
//

#import "SSDetailsHeadImageView.h"
#import <SDCycleScrollView.h>
#import "SSFocus.h"

@interface SSDetailsHeadImageView()<SDCycleScrollViewDelegate>

@property(nonatomic, strong) SDCycleScrollView *headImageView;
@property(nonatomic, strong) NSMutableArray *focusImageArr;
@property(nonatomic, strong) UILabel *buyNumLabel;

@end

@implementation SSDetailsHeadImageView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.headImageView];
        [self addSubview:self.buyNumLabel];
        
        
        #pragma mark - 约束
        __weak typeof (self) weakSelf = self;
        [_buyNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(85, 22));
            make.bottom.equalTo(weakSelf.mas_bottom).offset(-30);
            make.right.equalTo(weakSelf.mas_right).offset(11);
        }];
    }
    return self;
    
}


#pragma mark -
#pragma mark - 懒加载
- (SDCycleScrollView *)headImageView{
    if (!_headImageView) {
        // 网络加载 --- 创建带标题的图片轮播器
        _headImageView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, [UIScreen ss_screenWidth], 230) delegate:self placeholderImage:[UIImage imageNamed:@"icomImage"]];
        // >>>>>>>>>>>>>>>>>>>>>>>>> demo轮播图2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        
        _headImageView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _headImageView.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
        _headImageView.autoScroll = NO;
        
        [SSFocus loadFocusData:^(NSArray<SSFocus *> *data) {
            //            self.focusArr = data;
            for (SSFocus *focus in data) {
                [self.focusImageArr addObject:focus.img];
                
            }
            _headImageView.imageURLStringsGroup = self.focusImageArr.copy;
        }];
    }
    return _headImageView;
}

- (NSMutableArray *)focusImageArr{
    if (!_focusImageArr) {
        _focusImageArr = [NSMutableArray array];
        
    }
    return _focusImageArr;
}


- (UILabel *)buyNumLabel{
    if (!_buyNumLabel) {
        _buyNumLabel = [[UILabel alloc] init];
        _buyNumLabel.text = @"1222人购买";
        _buyNumLabel.backgroundColor = [UIColor ss_colorWithRed:230 green:51 blue:37];
        _buyNumLabel.textColor = [UIColor whiteColor];
        _buyNumLabel.font = [UIFont systemFontOfSize:11.0];
        _buyNumLabel.layer.masksToBounds = YES;
        _buyNumLabel.layer.cornerRadius = 11.0;
        _buyNumLabel.textAlignment = NSTextAlignmentCenter;
        
        
    }
    return _buyNumLabel;
}

@end
